package com.wechat.order.config.BeanConfig.WeChat;

import com.wechat.order.config.ConstantConfig.WeChatAccountConfig;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 微信开放平台正版扫码登陆sdk配置
 * Created by zzy on 2017/12/20.
 */
@Component
public class WeChatOpenConfig {

    @Autowired
    private WeChatAccountConfig weChatAccountConfig;

    @Bean
    public WxMpService wxMpOpenService(){
        WxMpService wxMpOpenService=new WxMpServiceImpl();
        wxMpOpenService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpOpenService;
    }

    @Bean
    public WxMpConfigStorage wxMpConfigStorage(){
        WxMpInMemoryConfigStorage wxMpConfigStorage=new WxMpInMemoryConfigStorage();
        wxMpConfigStorage.setAppId(weChatAccountConfig.getOpenAppId());
        wxMpConfigStorage.setSecret(weChatAccountConfig.getOpenAppSecret());
        return wxMpConfigStorage;
    }
}
